package com.example.springbootbabyu.mapper;

import com.example.springbootbabyu.entity.*;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface HomeMapper {
    // 查询所有一级分类
    @Select("SELECT id, name, picture FROM category WHERE layer = 1")
    List<Category> selectRootCategories();

    // 按分类ID查询商品
    @Select("SELECT id, name, picture FROM category WHERE parent_id = #{categoryId} AND layer = 2")
    List<Goods> selectGoodsByCategory(@Param("categoryId") String categoryId);

    @Select("SELECT * FROM hot")
    List<Hot> getHomeHot();
    // 查询所有品牌
    @Select("SELECT * FROM brand")
    List<Brand> selectBrands();

    @Select("SELECT * FROM new")
    List<New> getHomeNew();
    // 查询首页轮播图
    @Select("SELECT * FROM banner")
    List<Banner> getHomeBanner();

    // 查询一级分类
    @Select("SELECT id, name, picture, sale_info FROM category WHERE layer = 1")
    List<HomeGoods> selectTopCategories();

    // 查询子分类
    @Select("SELECT id, name, layer FROM category WHERE parent_id = #{parentId}")
    List<HomeGoodsChildren> selectChildrenByParentId(@Param("parentId") String parentId);

    // 查询分类下的商品
    @Select("SELECT id, name, `desc`, price, picture, order_num FROM goods WHERE category_id = #{categoryId}")
    List<HomeGoodsDTO> selectGoodsByCategoryId(@Param("categoryId") String categoryId);
}
